/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$("#LoginButton").click(function(){
    login();
});
$("#createAccountButton").click(function(){
    verifyCA();
})
function clearRed(){
    $(".createAccountInput").css("background-color","rgba(0,0,0,0)");
}
function verifyCA(){
    var b = 1;
    clearRed();
    if($("#firstName").val().trim() == ""){
        //Error
        b = 0;
        $("#firstName").css("background-color","#FF3636");
    }
    if($("#lastName").val().trim() == ""){
        //Error
        b = 0;
        $("#lastName").css("background-color","#FF3636");
    }
    
    //EMAIL VERIFICATION
    if($("#email").val().trim() == ""){
        //Error
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    else if(!$("#email").val().indexOf(".") == -1){
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    else if($("#email").val().indexOf("@") == 0){
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    else if(!$("#email").val().indexOf("@") == $("#email").val().lastIndexOf("@")){ //Only 1 @
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    else if($("#email").val().indexOf(".") == -1){
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    else if($("#email").val().lastIndexOf(".") == $("#email").val().length-1 || $("#email").val().lastIndexOf("@") > $("#email").val().lastIndexOf(".")){
        //Is there anything after the final . (usually some webending .com/.net/.tk) || is the final . after the @?
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    else if($("#email").val().lastIndexOf(".") == $("#email").val().lastIndexOf("@")+1){
        //Is there a char between the @ and the . (i.e is there a associated web domain name
        b = 0;
        $("#email").css("background-color","#FF3636");
    }
    //Password Verification
    if($("#password").val().trim() == ""){
        //Error
        b = 0;
        $("#password").css("background-color","#FF3636");
    }
    if($("#verifyPassword").val().trim()== ""){
        //Error
        b = 0;
        $("#verifyPassword").css("background-color","#FF3636");
    }
    if($("#password").val().trim() == "" && $("#verifyPassword").val().trim() == ""){
        //Error
        b = 0;
        $("#password").css("background-color","#FF3636");
        $("#verifyPassword").css("background-color","#F3636");
    }
    else if($("#password").val() != $("#verifyPassword").val()){
        //Error
        b = 0;
        if($("#password").val().trim() == ""){
            $("#password").css("background-color","#FF3636");
        }
        $("#verifyPassword").css("background-color","#FF3636");
    }
    
    //IS IT VALID?
    if(b == 1){
        $("#createForm").submit();//Submit the form!
    }
}
function login(){
    var b = 1;
    if($("#loginEmail").val() == ""){
        b = 0;
        $("#loginEmail").css("background-color","#FF3636");
    }
    if($("#loginPassword").val() == ""){
        b = 0;
        $("#loginPassword").css("background-color","#FF3636");
    }
    if(b == 1){
        $("#loginForm").submit();
    }
}
$("#LoginButton").hover(function(){
    $("#LoginButton").attr('src','images/loginButton_hover.png');
},function(){
    $("#LoginButton").attr('src','images/loginButton.png');
});
$("#createAccountButton").hover(function(){
    $("#createAccountButton").attr("src",'images/createAccountButton_hover.png');
},function(){
    $("#createAccountButton").attr("src","images/createAccountButton.png");
});